package com.dcd.controller;

import com.dcd.pojo.Video;
import com.dcd.service.VideoService;
import org.apache.solr.client.solrj.SolrServerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/VideoController")
public class VideoController {

    @Autowired(required = false)
    private VideoService videoService;

    /**
     * 查询所有视频和他的节目
     *
     * @param pageVideoindex 起始页
     * @return 返回所有视频, 节目名称, 总数量
     */
    @RequestMapping("/select_all_video_program")
    public Map<String, Object> select_all_video_program(@RequestParam Integer pageVideoindex, @RequestParam Integer video_type_id) {
        return videoService.select_all_video_program(pageVideoindex, video_type_id);
    }

    /**
     * 查询所有视频排行榜
     *
     * @return 返回前十视频
     */
    @RequestMapping("/91select_all_video_ranking")
    public List<Video> select_all_video_ranking() {
        return videoService.select_All_video_ranking();
    }

    /**
     * 根据车系id查询该车系所有视频
     *
     * @param car_series_id 车系id
     * @return
     */
    @RequestMapping("/select_series_id_video")
    public List<Video> select_series_id_video(@RequestParam Integer car_series_id) {
        return videoService.select_series_id_video(car_series_id);
    }

    /**
     * 查询最新的视频信息
     *
     * @return
     */
    @RequestMapping("/select_new_video_mess")
    public List<Video> select_new_video_mess() {
        return videoService.select_new_video_mess();
    }

    /**
     * 查询指定节目下指定车系视频
     *
     * @param program_id
     * @return
     */
    @RequestMapping("/select_appoint_program_all_video")
    public Map<String, Object> select_appoint_program_all_video(@RequestParam int program_id, @RequestParam int car_series_id, @RequestParam int page_index) {
        return videoService.select_appoint_program_all_video(program_id, car_series_id, page_index);
    }

    /**
     * 搜索查询视频
     *
     * @param solr_content 搜索文本内容
     * @param page_index   当前页数
     * @return
     */
    @RequestMapping("/select_video_by_solr")
    public Map<String, Object> select_video_by_solr(@RequestParam String solr_content, @RequestParam int page_index) throws IOException, SolrServerException {
        return videoService.select_video_by_solr(solr_content, page_index);
    }

    /**
     * 根据视频id 查询视频
     * 返回 视频名称，路径 简介，以及用户资料
     * @param video_id   视频id
     * @return
     */
    @RequestMapping("/select_videoByID_video")
    public Video select_videoByID_video(@RequestParam Integer video_id){
        return videoService.select_videoByID_video(video_id);
    }


    /**
     * 根据视频id 查询该节目所有视频
     * 返回 视频基本信息 / 节目名称
     * @param video_id
     * @return
     */
    @RequestMapping("/select_video_id_all")
    public List<Video> select_video_id_all(@RequestParam Integer video_id){
        return videoService.select_video_id_all(video_id);
    }
}
